home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / tde31.zip / TDEASM.C < prev    next >
C/C++ Source or Header  |  1993-08-29  |  7KB  |  206 lines

  1. /*
  2.  * The DTE 5.1 editor used a big text buffer for editing a file.  The big
  3.  * text buffer holds an image of a file pretty much as it appears on
  4.  * disk.  In that big buffer, '\0' was used to delimit the files.  In TDE
  5.  * versions 2.10 and less, a big text buffer was also used, but ^Z was used
  6.  * instead of '\0' to delimit files.  A double linked list is used in TDE 2.2
  7.  * to hold text.
  8.  *
  9.  * With these functions written in assembly, this editor is fairly fast.
  10.  * I feel the need for speed.
  11.  *
  12.  * New editor name:  TDE, the Thomson-Davis Editor.
  13.  * Author:           Frank Davis
  14.  * Date:             June 5, 1991, version 1.0
  15.  * Date:             July 29, 1991, version 1.1
  16.  * Date:             October 5, 1991, version 1.2
  17.  * Date:             January 20, 1992, version 1.3
  18.  * Date:             February 17, 1992, version 1.4
  19.  * Date:             April 1, 1992, version 1.5
  20.  * Date:             June 5, 1992, version 2.0
  21.  * Date:             October 31, 1992, version 2.1
  22.  * Date:             April 1, 1993, version 2.2
  23.  * Date:             June 5, 1993, version 3.0
  24.  * Date:             August 29, 1993, version 3.1
  25.  *
  26.  * This modification of Douglas Thomson's code is released into the
  27.  * public domain, Frank Davis.  You may distribute it freely.
  28.  */
  29.  
  30. #include "tdestr.h"
  31. #include "common.h"
  32. #include "tdefunc.h"
  33.  
  34.  
  35. /*
  36.  * Name:    ptoul - pointer to unsigned long
  37.  * Purpose: convert a far pointer to unsigned long integer
  38.  * Date:    June 5, 1991
  39.  * Passed:  s:  a far pointer
  40.  * Notes:   combine the offset and segment like so:
  41.  *                offset       0000
  42.  *                segment   + 0000
  43.  *                          =======
  44.  *                            00000
  45.  *          result is returned in dx:ax
  46.  */
  47. unsigned long ptoul( void far *s )
  48. {
  49.    ASSEMBLE {
  50.         mov     ax, WORD PTR s          /* ax = OFFSET of s */
  51.         mov     dx, WORD PTR s+2        /* dx = SEGMENT of s */
  52.         mov     bx, dx          /* put copy of segment in bx */
  53.         mov     cl, 12          /* cl = decimal 12 - shift hi word 3 hex digits */
  54.         shr     dx, cl          /* convert to 'real segment' */
  55.         mov     cl, 4           /* cl = 4  - shift hi word 1 hex digit left */
  56.         shl     bx, cl          /* shift bx - to add 3 digits of seg to 4 of off */
  57.         add     ax, bx          /* add low part of segment to offset */
  58.         adc     dx, 0           /* if carry, bump to next 'real' segment */
  59.    }
  60. }
  61.  
  62.  
  63. /*
  64.  * Name:    tabout
  65.  * Purpose: Expand tabs in display line
  66.  * Date:    October 31, 1992
  67.  * Passed:  s:  string pointer
  68.  *          len:  pointer to current length of string
  69.  * Notes:   Expand tabs in the display line according to current tab.
  70.  *          If eol display is on, let's display tabs, too.
  71.  */
  72. text_ptr tabout( text_ptr s, int *len )
  73. {
  74. text_ptr to;
  75. int space;
  76. int col;
  77. int i;
  78. int tab_size;
  79. int show_tab;
  80. int tab_len;
  81.  
  82.  
  83.    tab_size = mode.ptab_size;
  84.    show_tab = mode.show_eol;
  85.    to  = (text_ptr)g_status.tabout_buff;
  86.    i = tab_len  = *len;
  87.  
  88.    ASSEMBLE {
  89.         push    si
  90.         push    di
  91.         push    ds
  92.         push    es
  93.  
  94.         mov     bx, WORD PTR tab_size   /* keep tab_size in bx */
  95.         xor     cx, cx                  /* keep col in cx */
  96.  
  97.         mov     di, WORD PTR to
  98.         mov     ax, WORD PTR to+2
  99.         mov     es, ax                  /* es:di == to or the destination */
  100.         mov     si, WORD PTR s
  101.         mov     ax, WORD PTR s+2
  102.         mov     ds, ax                  /* ds:si == s or the source */
  103.    }
  104. top:
  105.  
  106.    ASSEMBLE {
  107.         cmp     cx, MAX_LINE_LENGTH     /* are at end of tabout buffer? */
  108.         jge     get_out
  109.  
  110.         cmp     WORD PTR i, 0           /* are at end of string? */
  111.         jle     get_out
  112.  
  113.         lodsb                           /* al == BYTE PTR ds:si */
  114.         cmp     al, 0x09                /* is this a tab character? */
  115.         je      expand_tab
  116.  
  117.         stosb                           /* store character in es:di inc di */
  118.         inc     cx                      /* increment col counter */
  119.         dec     WORD PTR i              /* decrement string counter */
  120.         jmp     SHORT top
  121.    }
  122. expand_tab:
  123.  
  124.    ASSEMBLE {
  125.         mov     ax, cx
  126.         xor     dx, dx                  /* set up dx:ax for IDIV */
  127.         IDIV    bx                      /* col % tab_size */
  128.         mov     ax, bx                  /* put tab_size in bx */
  129.         sub     ax, dx                  /* ax = tab_size - (col % tab_size) */
  130.         mov     dx, ax                  /* put ax in dx */
  131.         add     cx, ax                  /* col += space */
  132.         cmp     cx, MAX_LINE_LENGTH     /* is col > MAX_LINE_LENGTH? */
  133.         jge     get_out                 /* yes, get out */
  134.         mov     ax, ' '                 /* save blank character in ax */
  135.         cmp     WORD PTR show_tab, 0    /* was show_tab flag set? */
  136.         je      do_the_tab
  137.         mov     ax, 0x09                /* put tab character in ax */
  138.    }
  139. do_the_tab:
  140.  
  141.    ASSEMBLE {
  142.         stosb                           /* store in es:di and incr di */
  143.         dec     dx
  144.         cmp     dx, 0                   /* any spaces left to fill? */
  145.         jle     end_of_space            /* no, get another character */
  146.         add     WORD PTR tab_len, dx    /* add spaces to string length */
  147.         mov     ax, ' '                 /* save blank character in ax */
  148.    }
  149. space_fill:
  150.  
  151.    ASSEMBLE {
  152.         cmp     dx, 0                   /* any spaces left to fill? */
  153.         jle     end_of_space            /* no, get another character */
  154.         stosb                           /* store ' ' in es:di and incr di */
  155.         dec     dx                      /* space-- */
  156.         jmp     SHORT space_fill        /* fill space */
  157.   }
  158. end_of_space:
  159.  
  160.    ASSEMBLE {
  161.         dec     WORD PTR i
  162.         jmp     SHORT top
  163.    }
  164. get_out:
  165.  
  166.    ASSEMBLE {
  167.         pop     es
  168.         pop     ds
  169.         pop     di
  170.         pop     si
  171.    }
  172.    if (tab_len > MAX_LINE_LENGTH)
  173.       tab_len = MAX_LINE_LENGTH;
  174.    *len = g_status.tabout_buff_len = tab_len;
  175.    return( (text_ptr)g_status.tabout_buff );
  176.  
  177. /*
  178.    tab_size = mode.ptab_size;
  179.    show_tab = mode.show_eol;
  180.    to  = g_status.tabout_buff;
  181.    i = tab_len  = *len;
  182.    for (col=0; col < (MAX_LINE_LENGTH - (tab_size+1)) &&  i > 0; s++, i--) {
  183.       if (*s != '\t') {
  184.          *to++ = *s;
  185.          ++col;
  186.       } else {
  187.          space = tab_size - (col % tab_size);
  188.          col += space;
  189.          space--;
  190.          if (space > 0)
  191.             tab_len += space;
  192.          if (show_tab)
  193.             *to++ = '\t';
  194.          else
  195.             *to++ = ' ';
  196.          for (; space > 0; space--)
  197.             *to++ = ' ';
  198.       }
  199.    }
  200.    if (tab_len > MAX_LINE_LENGTH)
  201.       tab_len = MAX_LINE_LENGTH;
  202.    *len = g_status.tabout_buff_len = tab_len;
  203.    return( (text_ptr)g_status.tabout_buff );
  204. */
  205. }
  206.